<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细</title>
	<script src="../js/jquery.min.js"></script>
	<script src="data/webData.js"></script>
	<script src="js/jquery-3.1.1.min.js"></script>
	<script src="dropdown.js"></script>
	<link rel="stylesheet" href="dropdown.css">
	<link rel="stylesheet" href="layui-v2.6.8/layui/css/layui.css">
	<script src="layui-v2.6.8/layui/layui.js"></script>
</head>
<body>
     <div id="divMain1">

	 </div>
	 <div id="divMain2">

	 </div>
</body>
<script type="text/javascript">
	function getQueryVariable(variable)
	{
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if(pair[0] == variable){return pair[1];}
		}
		return(false);
	}
	$(function () {
        let sensorPID=parseInt(getQueryVariable("sensorPid")) ;
        let deviceId=getQueryVariable("deviceId");
		let result=sensorServer.getBatteryListByPage({"page":1,"rows":1000});

		let table="<table class='layui-table'>";
		table+="<tr><td>地点</td><td>1路电压</td><td>2二路电压</td><td>3路电压</td><td>时间</td></tr>"
		for (let i=0;i<result.data.length;i++){
			if(result.data[i].sensorPid==parseInt(sensorPID)){
				table+="<tr><td>"+result.data[i].deviceLocation+"</td><td>"
						+result.data[i].voltage1+"</td><td>"
						+result.data[i].voltage2+"</td><td>"
						+result.data[i].voltage3+"</td><td>"
						+result.data[i].updateTime+"</td></tr>";

			}
		}
		table+="</table>";
		$("#divMain1").html(table);
		//实时数据
		table="<table class='layui-table'>";
		table+="<tr><td>地点</td><td>CH4</td><td>CO2</td><td>CO</td><td>温度</td><td>湿度</td><td>氧气</td><td>时间</td></tr>";

		let date = new Date()
		let year = date.getFullYear()
		let month = (date.getMonth()+1).toString().padStart(2,'0')
		let day = date.getDate().toString().padStart(2,'0')
		var time = year+'-'+month+'-'+day

		let startTime=time+" 00:00:00";
		let endTime  =time+" 23:59:59";
		let params={"page":1,"rows":10,"deviceId":deviceId,"month":year+'-'+month,"startTime":startTime,"endTime":endTime};
		let sensorData=sensorServer.getSensorDataListByPage(params);
		for (let i=0;i<sensorData.data.length;i++){
				table+="<tr><td>"+sensorData.data[i].deviceLocation+"</td><td>"
						+sensorData.data[i].ch4.toFixed(2)+"</td><td>"
						+sensorData.data[i].co2.toFixed(2)+"</td><td>"
						+sensorData.data[i].co+"</td><td>"
						+sensorData.data[i].temperature.toFixed(1)+"</td><td>"
						+sensorData.data[i].humidity.toFixed(1)+"</td><td>"
						+sensorData.data[i].o2.toFixed(1)+"</td><td>"
						+sensorData.data[i].uploadtime+"</td></tr>";
				break;
		}
		$("#divMain2").html(table);

	})
</script>
</html>
